define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template', 'form'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template, Form) {

    var Controller = {
        index: function () {
            Controller.api.bindevent();
            $('#button1').on('click',function (e) {
                var load = Layer.load();
                var city = $('#c-jrgk_city').val();
                var date = $('#c-jrgk_date').val();
                var salesman_admin_id = $('#c-jrgk_salesman_admin_id option:selected').val();
                console.log(city,date,salesman_admin_id)

                $.ajax({
                    url:"/hFtNsJROTk.php/dashboard/dailyOverview",
                    data: { city: city, date: date, salesman: salesman_admin_id },
                    success:function(result){
                    var data = result.data;
                    $('#jrgk_dzfje').text(data.dzfje)
                    $('#jrgk_jjrsy').text(data.jjrsy)
                    $('#jrgk_mexh').text(data.mexh)
                    $('#jrgk_sjsy').text(data.sjsy)
                    $('#jrgk_xtlr').text(data.xtlr)
                    $('#jrgk_xzyxdp').text(data.xzyxdp)
                    // $('#jrgk_yzmexhl').text(data.yzmexhl)
                    $('#jrgk_zxdp').text(data.zxdp)
                    $('#jrgk_ptfwf').text(data.ptfwf)
                    // $('#jrgk_zxyzdp').text(data.zxyzdp)
                    Layer.close(load);
                }});
            })
            $('#button2').on('click',function (e) {
                var load = Layer.load();
                
                var city = $('#c-bygk_city').val();
                var date = $('#c-bygk_date').val();
                var salesman_admin_id = $('#c-bygk_salesman_admin_id option:selected').val();
                console.log(city,date,salesman_admin_id)

                $.ajax({
                    url:"/hFtNsJROTk.php/dashboard/salesOrder",
                    data: { city: city, date: date, salesman: salesman_admin_id },
                    success:function(result){
                        var data = result.data.channels;
                        var html = ''
                        $('#xd').find('.sm-st-info').each(function (i,j) {
                            console.log(i,data[i])
                            html='<p style="margin: 0 0 0px;">'+data[i].yxd+'/'+data[i].zl+' ('+data[i].xdbfb+'%)</p><p style="margin: 0 0 0px;">金额：'+data[i].dsje+'/'+data[i].dfje+'</p><p style="margin: 0 0 0px;">渠道：'+data[i].name+'</p>'
                            $('#xd').find('.sm-st-info').eq(i).html(html)
                        })
                        Layer.close(load);
                    }
                });
            })
            $('#button3').on('click',function (e) {
                var load = Layer.load();
                
                var date = $('#c-qdjs_date').val();

                $.ajax({
                    url:"/hFtNsJROTk.php/dashboard/salesOrder",
                    data: { date: date },
                    success:function(result){
                        var data = result.data.ywy;
                        var html = ''
                        $('#qdjs').find('.sm-st-info').each(function (i,j) {
                            console.log(i,data[i],j)
                            html='<p style="margin: 0 0 0px;">'+data[i].yxd+'/'+data[i].zl+' ('+data[i].xdbfb+'%)</p><p style="margin: 0 0 0px;">金额：'+data[i].dsje+'/'+data[i].dfje+'</p><p style="margin: 0 0 0px;">渠道业务员：'+data[i].nickname+'</p>'
                            $('#qdjs').find('.sm-st-info').eq(i).html(html)
                        })
                        Layer.close(load);
                    }
                });
            })

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };

    return Controller;
});
